package com.sky.controller.admin;


import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@Api("店铺营业状态设置")
@RequiredArgsConstructor
public class ShopController {


    private final RedisTemplate redisTemplate;

    private final static String REDIS_STATUS_KEY = "SHOP-STATUS";

    @PutMapping("/admin/shop/{status}")
    @ApiOperation("设置店铺状态")
    public Result setStatus(@PathVariable Integer status){
        log.info("设置店铺状态：{}",status);
        redisTemplate.opsForValue().set("REDIS_STATUS_KEY",status);
        return Result.success();
    }

    @GetMapping("/admin/shop/status")
    @ApiOperation("获取店铺状态")
    public Result getStatus(){
        Integer status = (Integer)redisTemplate.opsForValue().get("REDIS_STATUS_KEY");
        return Result.success(status);
    }

    @GetMapping("/user/shop/status")
    @ApiOperation("用户端获取店铺状态")
    public Result userGetStatus(){
        Integer status = (Integer)redisTemplate.opsForValue().get("REDIS_STATUS_KEY");
        return Result.success(status);
    }

}
